#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1e5 + 10;

//线段树


int n, m;
LL q[N];
struct Node
{
    int l, r;
    LL add, sum;
}node[N * 4];

void pushup(int u){
    node[u].sum = node[u << 1].sum + node[u << 1 | 1].sum;
}

void upd(Node& node, LL k){
    node.add += k;
    node.sum += (node.r - node.l + 1) * k;
}

void pushdown(int u){
    LL k = node[u].add;
    upd(node[u << 1], k);
    upd(node[u << 1 | 1], k);
    node[u].add = 0;
}

void build(int u, int l, int r){
    node[u].l = l, node[u].r = r;
    if(l == r){
        node[u].add = 0;
        node[u].sum = q[l];
        return;
    }
    int mid = l + r >> 1;
    build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
    pushup(u);
}


void modify(int u, int l, int r, LL k){
    if(node[u].l >= l && node[u].r <= r){
        node[u].sum += (node[u].r - node[u].l + 1) * k;
        node[u].add += k;
    }else{
        pushdown(u);
        int mid = node[u].l + node[u].r >> 1;
        if(l <= mid) modify(u << 1, l, r, k);
        if(r > mid) modify(u << 1 | 1, l, r, k);
        pushup(u);
    }
}


LL query(int u, int l, int r){
    if(node[u].l >= l && node[u].r <= r){
        return node[u].sum;
    }else{
        pushdown(u);
        LL res = 0;
        int mid = node[u].l + node[u].r >> 1;
        if(l <= mid) res += query(u << 1, l, r);
        if(r > mid) res += query(u << 1 | 1, l, r);
        return res;
    }
}


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);


    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i ++) scanf("%lld", &q[i]);

    build(1, 1, n);

    int op, l, r;
    LL k;
    while(m --){
        scanf("%d%d%d", &op, &l, &r);
        if(op == 1){
            scanf("%lld", &k);
            modify(1, l, r, k);
        }else{
            LL res = query(1, l, r);
            printf("%lld\n", res);
        }
    }

    return 0;
}